<template>
	<view class="cu-item shadow item">
		<view class="cu-list menu-avatar">
			<view class="cu-item">
				<view class="image">
					<image :src="formatImg(cardInfo.logo)" mode='widthFix'></image>
				</view>
				<view class="flex-sub">
					<view class="flex flex-direction justify-between" style="height: 280rpx;">
						<view class="project-title">{{ cardInfo.title }}</view>
						<view class="company"><text class="text-gray">投资金额（元):￥</text><text class="text-pink">{{ cardInfo.money }}</text></view>
						<view class="">
							<button class=" btn cu-btn bg-orange flex-sub sm" @tap="downloadContract()">查看签署</button>
						</view>
					</view>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "index",
		props: {
			cardInfo: {
				type: Object
			}
		},
		data() {
			let that = this;
			return {
				imgUrl: that.$mConfig.assetsPath,
			};
		},
		methods: {
			async seeContract() {
				let res = await this.$apis.seeContract({
					id: this.cardInfo.id
				});
				console.log(res.url)
				this.$store.commit("SET_SRC", res.url);
				this.$mRouter.push({
					route: this.$mRoutesConfig.contractWeb
				})
			},
			async downloadContract() {
				let res = await this.$apis.downContract({
					id: this.cardInfo.id
				});
				console.log(res.res)
				uni.downloadFile({
					url: res.res, //仅为示例，并非真实的资源
					success(res) {
						console.log(res)
						// 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
						if (res.statusCode === 200) {
							const filePath = res.tempFilePath
							wx.openDocument({
								filePath: filePath,
								success: function(res) {
									// console.log('打开文档成功')
								}
							})
							// wx.showToast({
							// 	title: '下载成功',
							// 	icon: "none",
							// 	duration: 2000
							// })
						}
					}
				})
			},
			formatStatus(status) {
				console.log(status)
				switch (status) {
					case 1:
						return "已认证";
					case 0:
						return "未认证";
				}
			},
			formatImg(thumb) {
				return this.imgUrl + '/uploads/contract/' + thumb;
			}
		}
	};
</script>

<style lang="scss" scoped>
	.text-gray {
		color: #969696;
	}

	.item {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
		margin: 0 30rpx;
		overflow: hidden;
		box-shadow: 0rpx 10rpx 8rpx #FFB89A;
		/*阴影出现在元素的左侧*/
		border: 1px solid rgba(255, 114, 55, 1);
	}

	.project-title {
		font-size: 30rpx;
		font-family: PingFang SC;
		color: rgba(50, 50, 50, 1);
	}

	.company {
		font-size: 24rpx;
		font-family: PingFang SC;
		color: rgba(50, 50, 50, 1);
	}

	.status {
		font-size: 30rpx;
		font-family: PingFang SC;
		color: rgba(255, 106, 0, 1);
	}

	.image image {

		border-radius: 8rpx;
		width: 210rpx !important;
		height: 280rpx;
		margin: 0 !important;
		background: linear-gradient(-90deg, rgba(234, 238, 247, 1), rgba(146, 162, 187, 1));
	}

	.image {
		font-size: 0;
		margin: 0 30rpx 0 0 !important;
	}

	.cu-btn.sm {
		font-size: 24rpx;
		font-family: PingFang SC;
		color: rgba(255, 255, 255, 1);
	}
	.btn{
		height: 48rpx !important;
		width: 146rpx;
	}
	.bg-orange{
		border:2rpx solid rgba(255,113,53,1);
		border-radius:8rpx;
		color: rgba(255,113,53,1) !important;
		background: #FFFFFF;
	}
</style>
